<?php
session_start();
require_once("koneksi.php");
$email = $_POST['email'];
$pass = $_POST['password'];
$cekuser = mysql_query("SELECT * FROM anggota WHERE email = '$email'");
$jumlah = mysql_num_rows($cekuser);
$hasil = mysql_fetch_array($cekuser);
if($jumlah == 0) {
echo "email Belum Terdaftar!<br/>";
echo "<a href='daftar.php' target='main'>Daftar</a>";
} else {
if($pass <> $hasil['password']) 
{
	echo ("<SCRIPT LANGUAGE='JavaScript'>
        window.alert('You have entered an invalid password. Enter the correct details and try again. Do not forget that the password is case sensitive')
        window.location.href='index.php'
        </SCRIPT>"); 
	
	
} 
else
{
	$cekkunjungan = mysql_query("SELECT * FROM kunjungan WHERE tgl_kunjungan = curdate()");
    $jumlah = mysql_num_rows($cekkunjungan);
        if($jumlah == 0)
        {
            $simpankunjungan = mysql_query("INSERT INTO kunjungan(tgl_kunjungan, banyak_kunjungan) VALUES (curdate(), '1')");
        }
        else
        {
            $updatekunjungan = mysql_query("UPDATE kunjungan SET banyak_kunjungan = (banyak_kunjungan + '1') WHERE tgl_kunjungan = curdate()"); 
        }
	$_SESSION['email'] = $hasil['email'];
	$_SESSION['kunjungan'] = 'A';
	
	header ('location:index.php');
	
}
}
?>